package me.zhengjie.modules.system.service.mapstruct;

import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.system.domain.System;
import me.zhengjie.modules.system.service.dto.SystemDto;
import me.zhengjie.modules.system.service.mapstruct.convertor.impl.SystemConvertor;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.ReportingPolicy;

/**
 * SystemMapper
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper(componentModel = "spring", uses = {SystemConvertor.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface SystemMapper extends BaseMapper<SystemDto, System> {

    /**
     * mapstruct自动注入当前mapper到RequirementMapper
     *
     * @param requirementDesc /
     * @return /
     */
    @Named("requirementDescPenetrate")
    default String requirementDescPenetrate(String requirementDesc) {
        return requirementDesc;
    }

    /**
     * DTO转Entity
     *
     * @param dto /
     * @return /
     */
    @Override
    @Mappings({@Mapping(target = "systemName", source = "systemName", qualifiedByName = "systemNamePenetrate"),
            @Mapping(target = "systemId", expression = "java(systemConvertor.systemId2Integer(dto.getSystemId()))")})
    System toEntity(SystemDto dto);

    /**
     * Entity转DTO
     *
     * @param entity /
     * @return /
     */
    @Override
    @Mappings({@Mapping(target = "systemName", source = "systemName", qualifiedByName = "systemNamePenetrate"),
            @Mapping(target = "systemId", expression = "java(systemConvertor.systemId2String(entity.getSystemId()))")})
    SystemDto toDto(System entity);
}
